package com.sort;

/**
 * Created by Lxk on 2019/5/21.
 */
public class Quick {

    public static void quickSort(int[] arr, int lo, int hi){
        if(hi <= lo){
            return ;
        }

        int i = lo,j = hi+1;
        int base = arr[lo];
        while(true){
            while(base < arr[++i]){
                if(i == hi){
                    break;
                }
            }

            while(base > arr[--j]){
                if(j == lo){
                    break;
                }
            }

            if(i >= j){
                break;
            }

            swap(arr, i, j);
        }
        swap(arr, lo, j);

        quickSort(arr,lo,j-1);
        quickSort(arr,j+1,hi);

    }

    private static void swap(int[] arr,int i,int j){
        int val = arr[i];
        arr[i] = arr[j];
        arr[j] = val;
    }

}
